package install.ren.exercise.test.ruby;

import org.jruby.embed.PathType;
import org.jruby.embed.ScriptingContainer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhuyunhui
 * @date 2019-07-08 10:53
 */
public class LoadPathSample {
    private final static String jrubyhome = "/Users/jonny/soft/jruby";
    private final String filename =  "/Users/jonny/code/self-workspace/install-ren-exercise/src/test/resources/index.rb";

    private LoadPathSample() {
        ScriptingContainer container = new ScriptingContainer();
        List<String> loadPaths = new ArrayList();
        loadPaths.add(jrubyhome);

        loadPaths.add(jrubyhome + "/lib/ruby/gems/shared/gems/psd-3.9.0/lib");
        loadPaths.add(jrubyhome + "/lib/ruby/gems/shared/gems/psd-enginedata-1.1.1/lib");
        loadPaths.add(jrubyhome + "/lib/ruby/gems/shared/gems/hashie-3.6.0/lib");
        loadPaths.add(jrubyhome + "/lib/ruby/gems/shared/gems/chunky_png-1.3.11/lib");
        loadPaths.add(jrubyhome + "/lib/ruby/gems/shared/gems/xmp-0.2.0/lib");
        loadPaths.add(jrubyhome + "/lib/ruby/gems/shared/gems/nokogiri-1.5.11-java/lib");
        // JRuby 1.5.x
        container.setLoadPaths(loadPaths);
        // JRuby 1.4.0
        //container.getProvider().setLoadPaths(loadPaths);
        long start = System.currentTimeMillis();
        container.runScriptlet(PathType.ABSOLUTE, filename);
        System.out.println(System.currentTimeMillis() - start);
    }

    public static void main(String[] args) {
        new LoadPathSample();
    }
}
